const mongoose = require('mongoose');

let mongooseModel = mongoose.model('shopModel');

// 新增门店
module.exports.addShop = async (shop) => {
    let data1 = await mongooseModel.find({ name: shop.name });
    let data2 = await mongooseModel.find({ merchantName: shop.merchantName });
    if (data1.length == 0 && data2.length == 0) {
        return await mongooseModel.create(shop);
    } else {
        if(data1.length != 0){
            return {msg:'您的店铺名已被注册！'}
        }else if(data2.length != 0){
            return {msg:'您已经有店铺了！'}
        }
    }
}

// 获取门店
module.exports.getMerchant = async (merchant) => {
    return await mongooseModel.find(merchant);
}
// 删除门店
module.exports.deleteShop = async ({_id}) => {
    return await mongooseModel.deleteOne({_id});
}

// 修改门店
module.exports.updateShop = async ({_id,name,merchantName,desc,Type,address,registerMoney,state}) => {
    let data = await mongooseModel.updateOne({ _id }, { name,merchantName,desc,Type,address,registerMoney,state });
    console.log(data);
    return data;
}